'use strict';

const Controller = require('egg').Controller;

class WanxiangController extends Controller {
  async generate() {
    const { ctx } = this;
    const { prompt, ratio, n = 1 } = ctx.request.body;

    try {
      const result = await ctx.service.wanxiang.generate({
        prompt,
        ratio,
        n
      });

      ctx.body = result;
    } catch (error) {
      ctx.status = 500;
      ctx.body = {
        error: error.message || '图片生成失败'
      };
    }
  }
}

module.exports = WanxiangController;
